package com.juli.school.app.controller.module;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.juli.school.dao.entity.Pub;
import com.juli.school.service.bo.ContestBo;
import com.juli.school.service.bo.RecBo;
import com.juli.school.service.enums.EnumModule;
import com.juli.school.service.impl.ContestService;
import com.juli.school.service.impl.RecService;
import com.juli.school.utils.core.model.CommonResp;
import com.juli.school.utils.core.model.ListResp;
import com.juli.school.utils.core.model.PageResp;

/**
 * @Description: 竞赛活动控制器
 * @author Eve
 * @date 2017/9/6
 */
@Controller
@RequestMapping("/contest")
public class ContestController {
	
	@Resource
	ContestService contestService;
	
	@Resource
	RecService recService;
	
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody CommonResp<String> add(ContestBo contestBo) {
		return contestService.add(contestBo);
	}
	
	@RequestMapping(value="/update",method=RequestMethod.POST)
	@ResponseBody CommonResp<String> update(ContestBo contestBo) {
		return contestService.update(contestBo);
	}
	
	@RequestMapping("/delete")
	@ResponseBody CommonResp<String> delete(String stuId,String snStamp) {
		return contestService.delete(snStamp,stuId);
	}
	
	@RequestMapping("/listPage")
	@ResponseBody
	CommonResp<PageResp<Pub>> listPage(ContestBo contestBo) {
		return contestService.listPage(contestBo);
	}
	
	/**
	 * @Description: 增量查询信息列表
	 * @author gaoxiang
	 * @date 2017年9月16日 下午10:27:17
	 */
	@RequestMapping("/list")
	@ResponseBody CommonResp<ListResp<Pub>> list(ContestBo req) {
		req.setQueryAll(true);
		return contestService.list(req);
	}
	
	@RequestMapping("/detail")
	@ResponseBody
	CommonResp<ContestBo> detail(ContestBo contestBo) {
		return contestService.detail(contestBo);
	}
	
	@RequestMapping("detailer")
	public String detailer(ContestBo contestBo,ModelMap model){
		model.put("type", EnumModule.Contest);
		CommonResp<List<RecBo>> list = recService.list(contestBo.getSnStamp());
		model.put("recs", list.getData());
		model.put("obj",  contestService.detail(contestBo));
		return "/detail/index";
	}
}
